/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package View;

import Model.Ball;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JPanel;

/**
 *
 * @author Pro
 */
public class Display extends JPanel {

    Timer timer;
    private Ball[] balls;

    public Display() {


        //creat an place ball
        balls = new Ball[1000];

        for (int i = 0; i < balls.length; ++i) {
            balls[i] = new Ball();
            balls[i].place(800/2, 800/2);

        }

        timer = new Timer();

        TimerTask task = new TimerTask() {

            @Override
            public void run() {

                repaint();

            }
        };

        timer.schedule(task, 2000,5);

        setBackground(new Color(0x000000));

        setPreferredSize(new Dimension(800, 800));

    }

    @Override
    protected void paintComponent(Graphics g) {

        super.paintComponent(g);
//draw the ball

        for (Ball ball : balls) {

            //bounce ball
            ball.bounce(getWidth(), getHeight());
           
            // move ball
            ball.move();

             ball.draw(g);


        }

    }
}
